import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/bottom6_controller.dart';

class Bottom6View extends GetView<Bottom6Controller> {
  const Bottom6View({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      return Scaffold(
        appBar: AppBar(
          title: const Text('Flutter 自带菜单'),
          centerTitle: true,
        ),
        body: content(),
        floatingActionButton: FloatingActionButton(
          onPressed: () => debugPrint('点击了添加'),
          heroTag: 'home_bottomNaviageter',
          tooltip: '添加',
          backgroundColor: const Color(0xfff3799c),
          foregroundColor: Colors.white,
          elevation: 4,
          child: const Icon(Icons.add),
        ),
        floatingActionButtonLocation: controller.location,
        bottomNavigationBar: BottomAppBar(
          color: Colors.white,
          elevation: 8,
          shape: const CircularNotchedRectangle(),
          child: Row(
            children: <Widget>[
              space(controller.location ==
                  FloatingActionButtonLocation.startDocked),
              Expanded(
                  child: IconButton(
                    onPressed: () {
                      controller.onClickBottomBar(0);
                    },
                    icon: const Icon(Icons.access_alarm_outlined),
                    iconSize: 32,
                    color: controller.pageIndex.value == 0
                        ? const Color(0xfff3799c)
                        : Colors.grey,
                  )),
              space(controller.location ==
                  FloatingActionButtonLocation.centerDocked),
              Expanded(
                  child: IconButton(
                    onPressed: () {
                      controller.onClickBottomBar(1);
                    },
                    icon: const Icon(Icons.where_to_vote_rounded),
                    iconSize: 32,
                    color: controller.pageIndex.value == 1
                        ? const Color(0xfff3799c)
                        : Colors.grey,
                  )),
              space(controller.location ==
                  FloatingActionButtonLocation.endDocked),
            ],
          ),
        ),
        backgroundColor: Colors.grey[100],
      );
    });
  }

  Widget space(bool show) {
    return AnimatedContainer(
      duration: const Duration(milliseconds: 20),
      width: show ? 80 : 0,
      height: 0,
    );
  }

  Widget content() {
    return Obx(() {
      return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              controller.pageIndex.value.toString(),
              style: TextStyle(color: Colors.grey[400], fontSize: 80),
            ),
            GestureDetector(
              onTap: () {
                controller.setLocation();
              },
              child: const Chip(
                label: Text('更换按钮位置'),
                backgroundColor: Color(0xfff3799c),
                avatar: Icon(
                  Icons.cached,
                  color: Colors.white,
                ),
                labelStyle: TextStyle(color: Colors.white),
              ),
            )
          ],
        ),
      );
    });
  }
}
